.class final Lcom/burstly/lib/util/Crypto;
.super Ljava/lang/Object;
.source "Crypto.java"


# static fields
.field private static final AES:Ljava/lang/String; = "AES"

.field private static final ASCII:Ljava/lang/String; = "ASCII"


# direct methods
.method private constructor <init>()V
    .locals 0

    .prologue
    .line 42
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 43
    return-void
.end method

.method private static base64Decode([B)[B
    .locals 1
    .parameter "bytes"

    .prologue
    .line 147
    const/4 v0, 0x2

    invoke-static {p0, v0}, Lcom/burstly/lib/util/Base64;->decode([BI)[B

    move-result-object v0

    return-object v0
.end method

.method private static base64Encode([B)Ljava/lang/String;
    .locals 1
    .parameter "bytes"

    .prologue
    .line 137
    const/4 v0, 0x2

    invoke-static {p0, v0}, Lcom/burstly/lib/util/Base64;->encodeToString([BI)Ljava/lang/String;

    move-result-object v0

    return-object v0
.end method

.method private static copyOf([BI)[B
    .locals 3
    .parameter "original"
    .parameter "newLength"

    .prologue
    const/4 v2, 0x0

    .line 109
    new-array v0, p1, [B

    .line 110
    .local v0, copy:[B
    array-length v1, p0

    invoke-static {v1, p1}, Ljava/lang/Math;->min(II)I

    move-result v1

    invoke-static {p0, v2, v0, v2, v1}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V

    .line 111
    return-object v0
.end method

.method static decrypt(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 4
    .parameter "seed"
    .parameter "encrypted"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 68
    const-string v3, "ASCII"

    invoke-virtual {p0, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v1

    .line 69
    .local v1, rawKey:[B
    const-string v3, "ASCII"

    invoke-virtual {p1, v3}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v3

    invoke-static {v3}, Lcom/burstly/lib/util/Crypto;->base64Decode([B)[B

    move-result-object v0

    .line 70
    .local v0, enc:[B
    invoke-static {v1, v0}, Lcom/burstly/lib/util/Crypto;->decrypt([B[B)[B

    move-result-object v2

    .line 71
    .local v2, result:[B
    new-instance v3, Ljava/lang/String;

    invoke-direct {v3, v2}, Ljava/lang/String;-><init>([B)V

    return-object v3
.end method

.method private static decrypt([B[B)[B
    .locals 6
    .parameter "raw"
    .parameter "encrypted"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 123
    new-instance v2, Ljavax/crypto/spec/SecretKeySpec;

    const-string v3, "AES"

    invoke-direct {v2, p0, v3}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V

    .line 124
    .local v2, skeySpec:Ljavax/crypto/spec/SecretKeySpec;
    const-string v3, "AES/CBC/ZeroBytePadding"

    invoke-static {v3}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;

    move-result-object v0

    .line 125
    .local v0, cipher:Ljavax/crypto/Cipher;
    const/4 v3, 0x2

    new-instance v4, Ljavax/crypto/spec/IvParameterSpec;

    const/16 v5, 0x10

    new-array v5, v5, [B

    invoke-direct {v4, v5}, Ljavax/crypto/spec/IvParameterSpec;-><init>([B)V

    invoke-virtual {v0, v3, v2, v4}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V

    .line 126
    invoke-virtual {v0, p1}, Ljavax/crypto/Cipher;->doFinal([B)[B

    move-result-object v1

    .line 127
    .local v1, decrypted:[B
    return-object v1
.end method

.method static encrypt(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    .locals 3
    .parameter "seed"
    .parameter "rawId"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 54
    invoke-virtual {p0}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    .line 55
    .local v0, rawKey:[B
    const-string v2, "ASCII"

    invoke-virtual {p1, v2}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B

    move-result-object v2

    invoke-static {v0, v2}, Lcom/burstly/lib/util/Crypto;->encrypt([B[B)[B

    move-result-object v1

    .line 56
    .local v1, result:[B
    invoke-static {v1}, Lcom/burstly/lib/util/Crypto;->base64Encode([B)Ljava/lang/String;

    move-result-object v2

    return-object v2
.end method

.method private static encrypt([B[B)[B
    .locals 7
    .parameter "raw"
    .parameter "clear"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/lang/Exception;
        }
    .end annotation

    .prologue
    .line 84
    array-length v4, p1

    add-int/lit8 v4, v4, 0x1

    invoke-static {p1, v4}, Lcom/burstly/lib/util/Crypto;->copyOf([BI)[B

    move-result-object v3

    .line 85
    .local v3, toEncrypt:[B
    new-instance v2, Ljavax/crypto/spec/SecretKeySpec;

    const-string v4, "AES"

    invoke-direct {v2, p0, v4}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V

    .line 86
    .local v2, skeySpec:Ljavax/crypto/spec/SecretKeySpec;
    const-string v4, "AES/CBC/ZeroBytePadding"

    invoke-static {v4}, Ljavax/crypto/Cipher;->getInstance(Ljava/lang/String;)Ljavax/crypto/Cipher;

    move-result-object v0

    .line 87
    .local v0, cipher:Ljavax/crypto/Cipher;
    const/4 v4, 0x1

    new-instance v5, Ljavax/crypto/spec/IvParameterSpec;

    const/16 v6, 0x10

    new-array v6, v6, [B

    invoke-direct {v5, v6}, Ljavax/crypto/spec/IvParameterSpec;-><init>([B)V

    invoke-virtual {v0, v4, v2, v5}, Ljavax/crypto/Cipher;->init(ILjava/security/Key;Ljava/security/spec/AlgorithmParameterSpec;)V

    .line 88
    invoke-virtual {v0, v3}, Ljavax/crypto/Cipher;->doFinal([B)[B

    move-result-object v1

    .line 89
    .local v1, encrypted:[B
    return-object v1
.end method
